<template>
  <div >
  <div style="text-align: center" v-if="isShow">
    <el-form ref="form" :model="getCus" label-width="150px" style="text-align: center;width: 800px" label-position="left">
      <el-form-item label="顾客身份证号码">
        <el-input v-model.number="getCus.cid" ></el-input>
      </el-form-item>
      <el-button @click="onSubmit">进行修改</el-button>
    </el-form>
  </div>
    <div v-if="!isShow">
      <el-form ref="form" :model="cus" label-width="150px" style="text-align: center;width: 800px" label-position="left">
        <el-form ref="form" :model="cus" label-width="150px" style="text-align: left" >
          <el-form-item label="顾客姓名">
            <el-input v-model="cus.name"></el-input>
          </el-form-item>
          <el-form ref="form" :model="cus" label-width="150px" style="text-align: left" >
            <el-form-item label="顾客手机号码">
              <el-input v-model.number="cus.telnum"></el-input>
            </el-form-item>
            <el-form-item label="等级" >
              <el-select v-model.number="cus.grade" placeholder="选择优惠等级">
                <el-option label="普通" value=1></el-option>
                <el-option label="白银" value=2></el-option>
                <el-option label="黄金" value=3></el-option>
                <el-option label="钻石" value=4></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="updateCus">立即修改</el-button>
              <el-button @click="clearAll()">取消</el-button>
            </el-form-item>
          </el-form>
        </el-form>
      </el-form>

    </div>
  </div>
</template>
<script>
import instance from "@/untils";
export default {
  data() {
    return {
      getCus: {},
      isShow:true,
      cus:{}
    }
  },
  methods: {
    onSubmit() {
      instance.get("/cus/getById/"+this.getCus.cid).then(res=>{
            if(res.data.status==200){
              this.isShow=false;
              this.cus.cid=this.getCus.cid;
            }
          }
      )
    },
    clearAll(){
      this.cus={}
    },
    open() {
      this.$confirm('添加成功 是否回到主页面?', '提示', {
        cancelButtonText: '取消',
        confirmButtonText: '确定',
        type: 'success'
      }).then(() => {
        this.$router.push("/")
      }).catch(() => {
        this.clearAll();
      });
    },
    updateCus(){
      console.log(this.cus);
      instance.post('cus/update',this.cus).then(res=>{
          if(res.data.status==200){
            this.open();
          }
        })
    }

  }
}
</script>